package top.zhaojx.rpc.loadbalance.impl;

import top.zhaojx.rpc.entity.RpcRequest;
import top.zhaojx.rpc.loadbalance.AbstractLoadBalancer;

import java.util.List;

/**
 * 轮询
 */
public class RoundRobinLoadBalancer extends AbstractLoadBalancer {

    private int index = 0;

    @Override
    protected String doSelect(List<String> serviceAddresses, String serviceName) {
        index %= serviceAddresses.size();
        return serviceAddresses.get(index++);
    }
}
